/*
* ////////////////////////////////////////////////
*
* 开发者：AZPEP
* 友情链接：
*	-	B站：		零分的考卷			https://space.bilibili.com/257391258
*	-	Github：	AZPEP-BiliBili		https://github.com/AZPEP-BiliBili
*	-	Gitee：		AZPEP_BiliBili		https://gitee.com/AZPEP_BiliBili
*
* CopyRight AZPEP
*
* ////////////////////////////////////////////////
*/

#include "AST_QT.h"
#include <QTextCodec>
#include <QtWidgets/QApplication>
#include "Global_Include.h"

#pragma comment(lib, "Advapi32.lib")
#include <stdio.h>
#include <windows.h>

/*
#ifndef _DEBUG
#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" ) // 设置入口地址
#endif
*/
int main(int argc, char* argv[])
{
	
	//获取程序运行路径
	wchar_t WorkDirChar[512];
	_wgetcwd(WorkDirChar, 512);

	WorkDirPath = *new std::wstring(WorkDirChar);

	std::wstringstream ProgramPathWss;  //日志文件夹路径
	ProgramPathWss << WorkDirChar;
	ProgramPathW = *new std::wstring(ProgramPathWss.str());

	//获取系统亮暗色
	HKEY hKey;
	RegOpenKeyExA(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", 0, KEY_NOTIFY | KEY_READ, &hKey);
	DWORD dwSize = sizeof(DWORD);
	DWORD queryValue;
	RegQueryValueExA(hKey, "AppsUseLightTheme", NULL, NULL, (LPBYTE)&queryValue, &dwSize);
	if (queryValue == 1) LightMode = true;
	else LightMode = false;

	//初始化程序
	Init();

	//设置中文编码
#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0))
#if _MSC_VER
	QTextCodec* codec = QTextCodec::codecForName("GBK");
#else
	QTextCodec* codec = QTextCodec::codecForName("UTF-8");
#endif
	QTextCodec::setCodecForLocale(codec);
	QTextCodec::setCodecForCStrings(codec);
	QTextCodec::setCodecForTr(codec);
#else
	QTextCodec* codec = QTextCodec::codecForName("UTF-8");
	QTextCodec::setCodecForLocale(codec);
#endif

	//运行程序
	AstLog_WriteWarning(LogHandle, L"[RUNTIME]！！！程序开始正式运行！！！");
	QApplication a(argc, argv);
	AST_QT w;
	w.show();
	a.exec();
	AstLog_WriteWarning(LogHandle, L"[RUNTIME]！！！程序运行结束！！！");

	//程序退出
	AstLog_WriteWarning(LogHandle, L"[EXIT]！！！程序开始退出！！！");
	AstMountEsp_UnMountEfiPartitionW();
	AstLog_WriteMessage(LogHandle, L"[EXIT]软保护退出措施已完成！开始退出...");
	AstLog_StopService(LogHandle);
	std::exit(0);
}

